package com.qiche.handle;

import com.qiche.aspect.Result;
import com.qiche.exception.MySystemException;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class ExceptionHandle {
	@ExceptionHandler(value = Exception.class)
	@ResponseBody
	public Result handle(Exception e) {
		if(e instanceof MySystemException) {
			MySystemException mySystemException=(MySystemException)e;
			return Result.createByErrorCodeMessage(mySystemException.getCode(),mySystemException.getMessage());
		}else if(e instanceof UnauthorizedException){
			log.error("系统异常:"+e.getMessage());
			return Result.createByErrorMessage("您没有该权限");
		}else {
			e.printStackTrace();
			log.error("系统异常:"+e.getMessage());
			return Result.createByErrorMessage(e.getMessage());
		}
	
	}
}
